﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TouristAgencyDataLayer;

namespace TouristAgencyAsp
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List<Destination> dests = Destinations.GetDestinations().ToList();
                dests.Insert(0, new Destination() { Destination1 = "" });
                this.destinationDDL.DataSource = dests;
                this.destinationDDL.DataTextField = "Destination1";
                this.destinationDDL.DataValueField = "DestinationId";
                this.destinationDDL.SelectedIndex = 0;
                DataBind();
            }
        }

        protected void searchBtn_Click(object sender, EventArgs e)
        {

            var res = Tours.GetTours();
            if (this.minPriceTxt.Text != "")
            {
                res = res.Where(r => r.Price >= Convert.ToDecimal(this.minPriceTxt.Text));
            }
            if (this.maxPriceTxt.Text != "")
            {
                res = res.Where(r => r.Price <= Convert.ToDecimal(this.maxPriceTxt.Text));
            }
            if (this.destinationDDL.SelectedIndex != 0)
            {
                res = res.Where(r => r.DestinationId == Convert.ToInt32(destinationDDL.SelectedValue));
            }
            if (this.startTxt.Text != "")
            {
                res = res.Where(r => r.StartDate == Convert.ToDateTime(this.startTxt.Text));
            }
            if (this.endTxt.Text != "")
            {
                res = res.Where(r => r.EndDate == Convert.ToDateTime(this.endTxt.Text));
            }

            this.resRepeater.DataSource = res;
            DataBind();
        }
    }
}